package com.woniuxy.mesboot.controller;

import com.woniuxy.mesboot.entity.MatType;
import com.woniuxy.mesboot.entity.Storage;
import com.woniuxy.mesboot.service.MatOutService;
import com.woniuxy.mesboot.service.MatTypeService;
import com.woniuxy.mesboot.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("mattype")
public class MatTypeController {
    @Resource
    private MatTypeService matTypeService;
    @GetMapping
    public Result queryAll(){
         List<MatType> matTypes =matTypeService.selectAll();
        return Result.ok().data("list",matTypes);
    }
    @PostMapping()
    public Result insert(@RequestBody MatType matType) {
        int i =matTypeService.insertSelective(matType);
        if (i > 0) {
            return Result.ok("添加成功");
        } else {
            return Result.error("添加失败");
        }
    }

    @GetMapping("{id}")
    public Result queryById(@PathVariable Long id) {
        MatType matType = matTypeService.selectByPrimaryKey(id);
        return Result.ok().data("item", matType);

    }

    @DeleteMapping("{id}")
    public Result delete(@PathVariable Long id) {
        int i = matTypeService.deleteByPrimaryKey(id);
        if (i > 0) {
            return Result.ok("删除成功");

        } else {
            return Result.error("删除失败");
        }


    }

    @PutMapping
    public Result update(@RequestBody MatType orders) {
        int i = matTypeService.updateByPrimaryKeySelective(orders);
        if (i > 0) {
            return Result.ok("修改成功");

        } else {
            return Result.error("修改失败");
        }
    }
}
